package com.hnust.controller.subject.dialog;

import com.hnust.domain.AlternativeAnswerRecord;
import com.hnust.domain.BulkImport;
import com.hnust.fx.FXMLController;
import com.hnust.store.DataStore;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.GridPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

/**
 * @program: demo
 * @author: 彭鑫淼
 * @description: 未知
 * @create: 2020-11-01 12:51
 */
@FXMLController
public class WindowPaperController implements Initializable {
    public WebView answer;
    @FXML
    GridPane ap;
    @FXML
    WebView level;
    @FXML
    WebView quetyp;
    @FXML
    WebView course;
    @FXML
    WebView chapter;
    @FXML
    WebView point;
    @FXML
    WebView target;
    @FXML
    WebView content;
    @FXML
    WebView analysis;
    @Autowired
    private DataStore dataStore;
    private BulkImport data;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        ap.parentProperty().addListener((observable, oldValue, newValue) -> {
            if(newValue!=null){
                data=dataStore.getBulkImport();
                ShowContent();
                ShowPoint();
                ShowAnalysis();
                ShowTarget();
                ShowChapter();
                ShowCourse();
                ShowQueTypId();
                ShowLevel();
                showAnswer();
            }
        });
    }

    private void showAnswer() {
        WebEngine webEngine=answer.getEngine();
        StringBuilder content= new StringBuilder();
        List<AlternativeAnswerRecord> list=data.getAnswerList();
        for (AlternativeAnswerRecord alternativeAnswerRecord : list) {
            if (alternativeAnswerRecord.getRight() == 1) {
                content.append(alternativeAnswerRecord.getContent()).append("<br/>");
            }
        }
        webEngine.loadContent(content.toString());
    }

    public String getKind() {
        return "选择题";
    }
    //显示题目类型
    public void ShowQueTypId(){
        WebEngine webEngine=quetyp.getEngine();
        String content="";
        String st=data.getQueTypId();
        content=content+st;
        webEngine.loadContent(content);
    }
    //显示题目难度
    public void ShowLevel(){
        WebEngine webEngine=level.getEngine();
        String content="";
        int i=data.getLevel();
        content=content+i;
        webEngine.loadContent(content);
    }
    //显示课程
    public void ShowCourse(){
        WebEngine webEngine=course.getEngine();
        String content="";
        String st=data.getCouId();
        content=content+st;
        webEngine.loadContent(content);
    }
    //显示章节
    public void ShowChapter(){
        WebEngine webEngine=chapter.getEngine();
        String content="";
        String st=data.getChaId();
        content=content+st;
        webEngine.loadContent(content);
    }
    //显示课程目标
    public void ShowTarget(){
        WebEngine webEngine=target.getEngine();
        String content="";
        String st=data.getCouTarId();
        content=content+st;
        webEngine.loadContent(content);
    }
    //显示题目内容
    public void ShowContent(){
        WebEngine webEngine=content.getEngine();
        String content="";
        String st=data.getContent();
        content=content+st;
        webEngine.loadContent(content);
    }
    //显示知识点
    public void ShowPoint(){
        WebEngine webEngine=point.getEngine();
        String content="";
        String st=data.getPoint();
        content=content+st;
        webEngine.loadContent(content);
    }
    //显示解析
    public void ShowAnalysis(){
        WebEngine webEngine=analysis.getEngine();
        String content="";
        String st=data.getAnalysis();
        content=content+st;
        webEngine.loadContent(content);
    }
}
